package com.jerry.springcloud.controller;

import com.jerry.springcloud.bean.Category;
import com.jerry.springcloud.bean.Product;
import com.jerry.springcloud.enums.ResultEnum;
import com.jerry.springcloud.exception.SellerException;
import com.jerry.springcloud.service.CategoryService;
import com.jerry.springcloud.service.ProductService;
import com.jerry.springcloud.utils.ResultVoUtil;
import com.jerry.springcloud.vo.ProductVo;
import com.jerry.springcloud.vo.ResultVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.validation.Valid;
import javax.xml.transform.Result;
import java.util.List;
import java.util.Map;

/**
 * 卖家端商品
 */
@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;
    @Autowired
    private CategoryService categoryService;

    //列表
    @GetMapping("/list")
    public ResultVo<List<Product>> list() {
        List<Product> productAllList = productService.findAll();
        return ResultVoUtil.success(productAllList);
    }

    //保存/更新
    @PostMapping("/addOrUpdate")
    public Product addOrUpdate(Product product) {
        return productService.saveOrUpdate(product);
    }

    //商品上架
    @RequestMapping("/onSale")
    public Product onSale(@RequestParam("id") String id) {
        return productService.onSale(id);
    }

    //商品下架
    @RequestMapping("/offSale")
    public Product offSale(@RequestParam("id") String id) {
        return productService.offSale(id);
    }

}
